import 'package:flutter/material.dart';
import 'package:get/get.dart';

void main(List<String> args) {
  runApp(CountDemo());
}

final count = 0.obs;

class CountDemo extends StatefulWidget {
  const CountDemo({Key? key}) : super(key: key);

  @override
  State<CountDemo> createState() => _CountDemoState();
}

class _CountDemoState extends State<CountDemo> {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: Text('CountDemo'),
        ),
        body: Center(
          child: Column(
            children: [
              Count(),
              Count2(),
            ],
          ),
        ),
        floatingActionButton: FloatingActionButton(
          onPressed: () {
            setState(() {});
          },
          child: Icon(Icons.add),
        ),
      ),
    );
  }
}

class Count extends StatefulWidget {
  const Count({Key? key}) : super(key: key);

  @override
  State<Count> createState() => _CountState();
}

class _CountState extends State<Count> {
  @override
  Widget build(BuildContext context) {
    return ElevatedButton(
      onPressed: () {
        count.value++;
      },
      child: Obx(
        () => Text(
          '$count++',
          style: TextStyle(
            fontWeight: FontWeight.bold,
            fontSize: 24,
            color: Colors.black87,
          ),
        ),
      ),
    );
  }
}

class Count2 extends StatefulWidget {
  const Count2({Key? key}) : super(key: key);

  @override
  State<Count2> createState() => _Count2State();
}

class _Count2State extends State<Count2> {
  @override
  Widget build(BuildContext context) {
    return ElevatedButton(
      onPressed: () {
        count.value--;
      },
      child: Obx(
        () => Text(
          '$count- -',
          style: TextStyle(
            fontWeight: FontWeight.bold,
            fontSize: 24,
            color: Colors.black87,
          ),
        ),
      ),
    );
  }
}
